import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Test2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {


        Callable<Integer> callable  = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int i = 0 ;
                for (int j = 0; j < 100; j++) {
                    i ++ ;
                }
                return i ;
            }
        };

        FutureTask<Integer> futureTask = new FutureTask<>(callable);
        Thread t1 = new Thread(futureTask);
         t1.start();
         // get获取 callable的返回值 ;
        System.out.println(futureTask.get());
        //get不用担心,主线程执行到get 导致 callable还没有执行完就输出 ;
        //get 会阻塞等待 , callable 执行完 ,才到get


    }
}
